﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Manon.Autofac;
using Manon.ConfigCenter.Web.ApplicationCore.Dtos.Environment;
using Manon.ConfigCenter.Web.ApplicationCore.Dtos.Project;
using Manon.ConfigCenter.Web.ApplicationCore.Dtos.Role;
using Manon.ConfigCenter.Web.ApplicationCore.Dtos.User;
using Manon.ConfigCenter.Web.ApplicationCore.Interfaces;
using Manon.Core.Commons;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Manon.ConfigCenter.Web.Controllers
{
    public class UserController : Controller
    {
        public IActionResult Index()
        {
            return View();
        } 

        public IActionResult Edit()
        {
            return View();
        }
        [Authorize]
        [HttpPost]
        public async Task<IPagedList<UserOutput>> GetUserPageList([FromBody] GetUserPageListInput Input)
        {

            var user = Resolver.Resolve<IUserService>();
            var result = await user.GetUserPageList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveUser([FromBody] SaveUserInput Input)
        {
            var user = Resolver.Resolve<IUserService>();
            var result = await user.SaveUser(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<UserOutput> GetUser(int UserId)
        {

            var user = Resolver.Resolve<IUserService>();
            var result = await user.GetUserById(UserId);
            return result;
        }


        [Authorize]
        [HttpPost]
        public async Task<Result> SetEnabled([FromBody] SetUserEnabledInput Input)
        {

            var user = Resolver.Resolve<IUserService>();
            var result = await user.SetEnabled(Input);
            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> ModifyPassword([FromBody] ModifyPasswordInput Input)
        {

            var user = Resolver.Resolve<IUserService>();
            var result = await user.ModifyPassword(Input);
            return result;
        }


        [Authorize]
        [HttpPost]
        public async Task<Result> BandUserRoles([FromBody] BandRoleInput Input)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.BandRoles(Input);

            return result;
        }

        [Authorize]
        [HttpGet]
        public async Task<List<string>> GetUserBandRoles(int UserId)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetUserBandRoles(UserId);
            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> BandUserEnvs([FromBody] BandUserEnvInput Input)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.BandRoleEnvs(Input);

            return result;
        }

        [Authorize]
        [HttpGet]
        public async Task<List<string>> GetUserBandEnvIds(int UserId)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetUserBandEnvIds(UserId);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> BandUserProjects([FromBody] BandUserProjectInput Input)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.BandRoleProjects(Input);

            return result;
        }

        [Authorize]
        [HttpGet]
        public async Task<List<string>> GetUserBandProjectIds(int UserId)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetUserBandProjectIds(UserId);
            return result;
        }


        [Authorize]
        [HttpGet]
        public async Task<List<EnvironmentSimpleOutput>> GetAllEnvironmentSimpleList()
        {

            var role = Resolver.Resolve<IEnvironmentService>();
            var result = await role.GetAllEnvironmentSimpleListAsync();
            return result;
        }

        [Authorize]
        [HttpGet]
        public async Task<List<ProjectSimpleOutput>> GetAllProjectSimpleList()
        {

            var role = Resolver.Resolve<IProjectService>();
            var result = await role.GetAllProjectSimpleListAsync();
            return result;
        }

    }
}
